<?php 

namespace app\web\controller;

use app\common\hrlper\VerifyHelper;
use think\Controller;
use think\Db;
use think\Request;


class Index
{
    // 首页
    public function index()
    {
        return view('index/app');
    }
    
    // 接口
    public function api()
    {
        $res = Db::table('my_user') ->field('username') ->select();
        return json($res);
    }
    
    public function verify()
    {
        VerifyHelper::verify();
    }

    //接口
    public function callapi()
    {
        $url = 'http://tp.local/api';
        $urlreq = new allRequest();
        $msg = $urlreq ->curl_request($url);
        dump(json_decode($msg));die;
    }

    // 门店
    public function store()
    {
        $data = model('TestModel') ->store();
        var_dump($data);
        return view('index/store',[
            'list' => $data
        ]);
    }

    public function search()
    {

        // var_dump();die;
        $data = model('TestModel') ->search();
        return view('index/store',[
            'list' => $data
        ]);
    }

    public function menu()
    {
        if (empty($_GET['title'])) {
            $res = Db::table('goods')->select();
            $list = Db::table('category')->where('pid',0)->select();
            return view('index/menu',[
                'list'=>$list,
                'res'=>$res
            ]);
        } else {
            $title = $_GET['title'];
            $list = Db::table('category')->where('pid',0)->select();
            $res = Db::table('goods')->where('name','like','%'.$title.'%')->select();
            // $this->assign('list', $list);
            return view('index/menu',[
                'list'=>$list,
                'res'=>$res
            ]);
        }
    }

    public function showgoods($id)
    {
        $list = model('TestModel') ->menu();
        $data = Db::table('category')->field('id')->where(' path like "%,'.$id.',%"')->select();
        // var_dump($data);die;
        $cid = '';
        foreach ($data as $k => $v) {
            $cid .= $v['id'].',';
        }
        $cid .= $id;
        $res = Db::table('goods')->where('goods_categroy_id in ('.$cid.')')->select();
        return view('index/menu',[
            'list'=>$list,
            'res'=>$res
        ]);
    }

    public function account()
    {
//      $data = model('TestModel') ->account();
        return view('index/account');
    }

    public function more()
    {
        return view('index/more');
    }
}









